<?php

use Codesleeve\Stapler\ORM\StaplerableInterface;
use Codesleeve\Stapler\ORM\EloquentTrait;

class Image extends Eloquent implements StaplerableInterface{
    
    use EloquentTrait;
    
    protected $guarded = ['id'];
    protected $fillable = ['title','img'];
    public $timestamps = false;
    
    public function __construct(array $attributes = array()) {
//        $this->hasAttachedFile('img', [
//            'styles' => [
//                'rel_main' => '1000x340#',
//                'rel_horizontal' => '1000x520#',
//                'rel_vertical' => '500x750#',
//                'rel_mini' => '330x170#',
//                'rel_list' => '500x240#',
//                'obj_mini' => '250x250#',
//                'obj_main' => '500x500#',
//                'apartment' => '500x330#'
//            ]
//        ]);
//
        parent::__construct($attributes);
    }
    
    public function objetos(){
        return $this->belongsToMany('Objeto')->withPivot('position');
    }
    
    public function getPosition() {
        return $this->objetos()->first()->pivot->position;
    }
    
    public static function validate($input) {
        $rules = ['file' => 'image|mimes:jpeg|max:2000'];
        return Validator::make($input, $rules);
    }
    
    public function getObjetoId() {
        return $this->objetos()->first()->id;
    }
}